﻿using UnityEngine;

namespace ProjectMyFarmAndShe
{
    public class AddSecondSeries
    {
        public static void AddChallenge(ChallengeSeries series)
        {
            var emailSystem = Global.Interface.GetSystem<IEmailSystem>();
            var toolBarSystem = Global.Interface.GetSystem<IToolbarSystem>();

            var firstChallenge = new ChallengeData()
                .WithKey("村口家的老爷爷的第一个的委托")
                .WithPublisher("村口家的老爷爷")
                .WithDescription("村口家的老爷爷脚得风寒,需要十个土豆应急。")
                .WithCurrentDay(Global.Day.Value)
                .WithUnlock((self) =>
                {
                    if (Global.Day.Value >= self.CurrentDay + 2)
                    {
                        return true;
                    }

                    return false;
                })
                .WithCondition(() =>
                {
                    if (Global.PotatoCount.Value >= 10)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.PotatoCount.Value -= 10;
                    toolBarSystem.SubToolbarData("Potato", 10);
                    Global.Coin.Value += 50;

                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("我是村口的老头子,最近天气变化莫测,我的老寒腿又开始闹腾了,行动不便,没法自己出门,家里存粮不多,眼下最紧要的就是需要十个新鲜的土豆," +
                                  "用于做些热乎乎的食物暖暖身子,很感谢你对我的帮助,因为这个脚啊迟迟不能出门,如果不是没有你的话我不知道该怎么办啊," +
                                  "等脚恢复得差不多了我会带酒来我们好好喝上一壶,到时候就要你准备下酒菜了,哈哈")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);

                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });

            var secondChallenge = new ChallengeData()
                .WithKey("村口家的老爷爷的第二个的委托")
                .WithPublisher("村口家的老爷爷")
                .WithDescription("村口家的老爷爷需要二十个土豆和十个粉色萝卜。")
                .WithUnlock((self) =>
                {
                    if (firstChallenge.Finished && Global.Day.Value >= firstChallenge.FinishedDay + 5)
                    {
                        return true;
                    }

                    return false;
                })
                .WithCondition(() =>
                {
                    if (Global.PotatoCount.Value >= 20 && Global.PinkRadishCount.Value >= 10)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.PotatoCount.Value -= 20;
                    Global.PinkRadishCount.Value -= 10;

                    toolBarSystem.SubToolbarData("Potato", 20);
                    toolBarSystem.SubToolbarData("PinkRadish", 10);

                    Global.Coin.Value += 60;

                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("上次我们一起喝酒用的那个下酒菜真的是让我想念啊,喝了这么久的酒了第一次能吃到这种下酒菜,我仔细品了一下应该是用土豆和只有你种植有的粉红色的萝卜。" +
                                  "于是我又来委托你了要了新鲜的土豆和你那里特有的粉红色萝卜,但是制作过程并不容易啊哈哈,老头子我用了最后两个土豆和三个粉色萝卜才做出来一模一样的味道," +
                                  "等我下次再来尝尝你上次喝酒时候说过的其他的下酒菜。")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);

                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });

            var thirdChallenge = new ChallengeData()
                .WithKey("村口家的老爷爷的第三个的委托")
                .WithPublisher("村口家的老爷爷")
                .WithDescription("村口家的老爷爷想要10个葡萄和10个蓝莓。")
                .WithUnlock((self) =>
                {
                    if (secondChallenge.Finished && Global.Day.Value >= secondChallenge.FinishedDay + 5)
                    {
                        return true;
                    }

                    return false;
                })
                .WithCondition(() =>
                {
                    if (Global.GrapeCount.Value >= 10 && Global.BlueBerryCount.Value >= 10)
                    {
                        return true;
                    }

                    return false;
                })
                .WithFinishedAction((self) =>
                {
                    Global.GrapeCount.Value -= 10;
                    Global.BlueBerryCount.Value -= 10;

                    toolBarSystem.SubToolbarData("Grape", 20);
                    toolBarSystem.SubToolbarData("BlueBerry", 10);

                    Global.Coin.Value += 100;

                    var emailData = new EmailData()
                        .WithTitle($"{self.Publisher}第{self.FinishedDay}天的感谢信")
                        .WithPublisher(self.Publisher)
                        .WithInfo("这个天太热了,家里又没有水果,之前路过的时候刚好看见你种了一些水果,就想着来委托你了,你是知道的,在热天吃水果是多么一种享受,再加上能做一壶水果酒,想必" +
                                  "一定很好喝,这次用了葡萄和蓝莓压烂之后直接泡在酒里,才第二天就出了一点香味,相信等过段时间就能喝了,到时候又来找你喝酒。")
                        .WithSendDay(self.FinishedDay + 1)
                        .WithRead(false);

                    emailSystem.AddEmail(emailData);

                    MessagePanel.Default.AddMessage($"{self.Key}完成");
                });

            series.AddChallenge(firstChallenge)
                .AddChallenge(secondChallenge)
                .AddChallenge(thirdChallenge);
        }
    }
}